home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Skunkware 5
/
Skunkware 5.iso
/
src
/
X11
/
xarchie-2.0.9
/
FWF
/
Dir
/
RegExp.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-06-18
|
3KB
|
123 lines
/****************************************************************************
RegExp.c
This file contains the C code for the regular expression
matching code.
The routines supported act as a more friendly, user level
interface to the regexp regular expression matching system.
****************************************************************************/
/*
* Copyright 1990,1991,1992 Brian Totty
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appears in all copies and that
* both that copyright notice and this permission notice appear in
* supporting documentation, and that the name of Brian Totty or
* University of Illinois not be used in advertising or publicity
* pertaining to distribution of the software without specific, written
* prior permission. Brian Totty and University of Illinois make no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
* Brian Totty and University of Illinois disclaim all warranties with
* regard to this software, including all implied warranties of
* merchantability and fitness, in no event shall Brian Totty or
* University of Illinois be liable for any special, indirect or
* consequential damages or any damages whatsoever resulting from loss of
* use, data or profits, whether in an action of contract, negligence or
* other tortious action, arising out of or in connection with the use or
* performance of this software.
*
* Author:
* Brian Totty
* Department of Computer Science
* University Of Illinois at Urbana-Champaign
* 1304 West Springfield Avenue
* Urbana, IL 61801
*
* totty@cs.uiuc.edu
*
*/
#include <RegExp.h>
#include <regexp.h>
void RegExpCompile(reg_exp,fsm_ptr,fsm_length)
char *reg_exp,*fsm_ptr;
int fsm_length;
{
#ifndef NO_REGEXP
compile(reg_exp,fsm_ptr,&(fsm_ptr[fsm_length]),'\0');
#endif
} /* End RegExpCompile */
int RegExpMatch(string,fsm_ptr)
char *string,*fsm_ptr;
{
#ifndef NO_REGEXP
if (advance(string,fsm_ptr) != 0)
return(TRUE);
else
return(FALSE);
#else
return(TRUE);
#endif
} /* End RegExpMatch */
void _RegExpError(val)
int val;
{
fprintf(stderr,"Regular Expression Error %d\n",val);
exit(-1);
} /* End _RegExpError */
void RegExpPatternToRegExp(pattern,reg_exp)
char *pattern,*reg_exp;
{
int in_bracket;
in_bracket = 0;
while (*pattern != '\0')
{
if (in_bracket)
{
if (*pattern == ']') in_bracket = 0;
*reg_exp++ = *pattern++;
}
else
{
switch (*pattern)
{
case '[':
in_bracket = 1;
*reg_exp++ = '[';
break;
case '?':
*reg_exp++ = '.';
break;
case '*':
*reg_exp++ = '.';
*reg_exp++ = '*';
break;
case '.':
*reg_exp++ = '\\';
*reg_exp++ = '.';
break;
default:
*reg_exp++ = *pattern;
break;
}
++ pattern;
}
}
*reg_exp++ = '$';
*reg_exp++ = '\0';
} /* End RegExpPatternToRegExp */